package spotGUI.utils;

import java.awt.image.BufferedImage;
import java.awt.image.RescaleOp;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.SwingConstants;

import utils.StackTracePrinter;

public class EmptyContentAreaButton extends JButton {

	public EmptyContentAreaButton (URL icon, String text) {
		setHorizontalTextPosition(SwingConstants.LEFT);
		setFocusPainted(false);
		setBorderPainted(false);
		setContentAreaFilled(false);
		setBorder(null);
		
		if (text != null)
			setText(text);
		setIcon(icon);
	}

	
	public void setIcon(URL icon) {
		super.setIcon(new ImageIcon(icon));
		try {
			ImageIcon brighter = increaseImageBrightness(ImageIO.read(icon));
			setRolloverIcon(brighter);
			setRolloverSelectedIcon(brighter);
			setPressedIcon(brighter);
		} catch (IOException e) {
			StackTracePrinter.print(e);
		}
	}
	
	 public static ImageIcon increaseImageBrightness(BufferedImage image) {
	        float[] factors = new float[] {
	            1.4f, 1.4f, 1.4f, 1.4f
	        };
	        float[] offsets = new float[] {
	            0.0f, 0.0f, 0.0f, 0.0f
	        };
	        RescaleOp op = new RescaleOp(factors, offsets, null);
	        BufferedImage brighter = op.filter(image, null);
	       return new ImageIcon(brighter);
	    }	
}
